package ast;

import java.io.PrintStream;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

import exceptions.FailedStdinReadException;

public class ReadFloatExpr extends Expr {
    public ReadFloatExpr(Location loc) {
        super(loc);
    }

    public void print(PrintStream ps) {
        ps.print("readfloat");
    }

    // interpret: prompt the user for a float and return it, if does not get desired input, throws an FailedStdinReadException
    public AbstractValue evaluate(Stack<Map<String, AbstractValue>> state, Scanner scanner) throws Exception {
        return AbstractValue.AnyFloat;
        /** 
        // init a float
        double f = 0.0;
        // try to read a float (double) from stdin
        try {
            if (scanner.hasNextDouble()) {
                f = scanner.nextDouble();
                return f;
            } else {
                throw new FailedStdinReadException("Failed to read a float from stdin");
            }
        } catch (Exception e) {
            throw new FailedStdinReadException("Failed to read a float from stdin");
        }
        */
    }
}
